//
//  BCApplicationVersionIconCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2019/1/16.
//  Copyright © 2019 guoshikeji. All rights reserved.
//

#import "BCApplicationVersionIconCell.h"

#import "NSBundle+AppInfo.h"

@interface BCApplicationVersionIconCell ()

@end

@implementation BCApplicationVersionIconCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    CGFloat conentH = 60.0f;
    //
    NSString *iconName = [NSBundle appIconName];
    if (iconName.length) {
        UIImage *iconImage = [UIImage imageNamed:iconName];
        if (iconImage) {
            self.iconIV = [UIImageView new];
            self.iconIV.image = iconImage;
            [self.contentView addSubview:self.iconIV];
            [self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.contentView).offset(15.0);
                make.centerY.mas_equalTo(self.contentView);
                make.width.height.mas_equalTo(conentH);
            }];
            self.iconIV.layer.cornerRadius = 10.0;
            self.iconIV.layer.masksToBounds = true;
        }
    }
    //
    self.versionLabel = [QMUILabel new];
    self.versionLabel.textColor = [UIColor qmui_colorWithHexString:@"#AEAEAE"];
    self.versionLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    self.versionLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.versionLabel];
    //
    if (self.iconIV) {
        [self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.iconIV.mas_right).offset(15.0);
            make.right.mas_equalTo(self.contentView).offset(-15.0);
            make.bottom.mas_equalTo(self.contentView.mas_centerY).offset(-4.0);
            
        }];
    }else {
        [self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView).offset(15.0);
            make.right.mas_equalTo(self.contentView).offset(-15.0);
            make.bottom.mas_equalTo(self.contentView.mas_centerY).offset(-4.0);
        }];
    }
    //
    self.buildLabel = [QMUILabel new];
    self.buildLabel.textColor = self.versionLabel.textColor;
    self.buildLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
    self.buildLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.buildLabel];
    [self.buildLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.versionLabel);
        make.top.mas_equalTo(self.contentView.mas_centerY).offset(4.0);
        make.right.mas_equalTo(self.versionLabel);
    }];
}
//

- (void)setCellModel:(BCApplicationInfoCellModel *)cellModel {
    [super setCellModel:cellModel];
    //
    self.versionLabel.text = BCLocalizedFormatString(@"Current Version:%@",[GeneralParameterManager sharedGeneral].appVersion);
    self.buildLabel.text = BCLocalizedFormatString(@"Build Bundle Version:%@",[GeneralParameterManager sharedGeneral].bundleVersion);
}



+ (CGFloat)defaultHeight {
    return 80.0f;
}

@end
